package com.itheima.controller.backend.security;

import com.itheima.common.entity.Result;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/ordersetting")
public class OrderSettingController {
    @Autowired
    private OrderSettingService orderSettingService;


    /**
     * 下载预约模板
     * @param response
     */
    @GetMapping("/download")
    public void download(HttpServletResponse  response,String filename) {
        log.info("下载预约模板");
        orderSettingService.export(response,filename);
    }

    /**
     * 上传文件
     * @param excelFile
     * @return
     */
    @PostMapping("/upload")
    public Result upload(@RequestParam("excelFile") MultipartFile excelFile) {
        log.info("上传预约模板");
        orderSettingService.upload(excelFile);
        return Result.success();
    }

    /**
     * 根据年月查询对应的预约设置信息
     * @return
     */
    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMonth(String month) {
        log.info("根据年月查询对应的预约设置信息");
        List<OrderSetting> list = orderSettingService.getOrderSettingByMonth(month);
        return Result.success(list);
    }

    /**
     * 根据日期修改可预约人数
     * @param orderSetting
     * @return
     */
    @PostMapping("/editNumberByOrderDate")
    public Result editNumberByOrderDate(@RequestBody OrderSetting orderSetting) {
        log.info("根据日期修改可预约人数");
        orderSettingService.editNumberByOrderDate(orderSetting);
        return Result.success();
    }
}
